package cn.fsd.controller;

import cn.fsd.query.dispatch.OrderQuery;
import cn.fsd.service.OrderService;
import cn.fsd.vo.OrderBean;
import cn.fsd.vo.PageBean;
import cn.fsd.vo.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/order",produces = "application/json;charset=utf-8")
@Api(value = "调度管理中有关订单的API",description = "调度管理中订单相关的功能")
public class OrderController {

    @Autowired
    OrderService orderService;

    @PostMapping("/page") //post + /order/page
    @ApiOperation(value = "调度安排页面订单列表的分页查询")
    public ResultBean findByPage(@RequestBody OrderQuery orderQuery){
        PageBean<OrderBean> pageBean = orderService.findByPage(orderQuery);
        return ResultBean.success(pageBean);
    }

    @PutMapping("/{order_id}") //put + /order/order_id
    @ApiOperation(value = "根据订单id进行订单状态修改")
    public ResultBean update(@PathVariable("order_id") String order_id){
        String msg = orderService.update(order_id);
        if("success".equals(msg)) return ResultBean.success();
        return ResultBean.error();
    }

//    @PostMapping("/transfer") //post + /order/transfer
//    @ApiOperation(value = "全部订单一键调度,******慎点")
//    public ResultBean transfer(){
//        String msg = orderService.transfer();
//        if("success".equals(msg)) return ResultBean.success();
//        return ResultBean.error();
//    }

    @PostMapping("/transferById/{order_id}") //post + /order/order_id
    @ApiOperation(value = "新建订单的实时调度,根据订单号进行当前订单的调度")
    public ResultBean transferById(@PathVariable("order_id") String order_id){
        String msg = orderService.transferById(order_id);
        if("success".equals(msg)) return ResultBean.success();
        return ResultBean.error();
    }

    @PostMapping("/transferAll") //post + /order/order_id
    @ApiOperation(value = "全部订单一键调度,实际只是修改了状态")
    public ResultBean transferAll(){
        String msg = orderService.transferAll();
        if("success".equals(msg)) return ResultBean.success();
        return ResultBean.error();
    }
}
